//
//  OERegisterDataController.m
//  OneEightyNine
//
//  Created by apple on 2019/3/3.
//  Copyright © 2019 stoneobs. All rights reserved.
//

#import "OERegisterDataController.h"

@implementation OERegisterDataController
+ (void)sendGetRegCodeRequestWithPhone:(NSString *)phone handle:(OERegisterDataNormalHandle)handle{
//    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    if (phone.length) {
        [paramDic setObject:phone forKey:@"mobile"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=Common&a=send_mobile_reg"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 if (handle) {
                                                     handle(YES,@"",nil);
                                                 }
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
+ (void)sendJudgeRegCodeCrrectRequestWithMobile:(NSString *)mobile mobile_code:(NSString *)mobile_code handle:(OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    [paramDic setObject:OE_PHONE_PREFIX forKey:@"prefix"];
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    if (mobile_code.length) {
        [paramDic setObject:mobile_code forKey:@"mobile_code"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=register"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
+ (void)sendRegisterRequestWithMobile:(NSString *)mobile password:(NSString *)password handle:(OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    [paramDic setObject:OE_PHONE_PREFIX forKey:@"prefix"];
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    if (password.length) {
        [paramDic setObject:password forKey:@"password"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=registerSecond"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
#pragma mark --发送找回密码验证码
+ (void)sendGetFindPwdCodeRequestWithMobile:(NSString *)mobile handle:(OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=Common&a=send_mobile_find"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 if (handle) {
                                                     handle(NO,@"",nil);
                                                 }
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
+ (void)sendJudgeFindPwdCodeCrrectRequestWithMobile:(NSString *)mobile mobile_code:(NSString *)mobile_code handle:(OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    [paramDic setObject:OE_PHONE_PREFIX forKey:@"prefix"];
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    if (mobile_code.length) {
        [paramDic setObject:mobile_code forKey:@"mobile_code"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=findPassword"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
+ (void)sendChangeFindPwdRequestWithMobile:(NSString *)mobile password:(nonnull NSString *)password handle:(nonnull OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    [paramDic setObject:OE_PHONE_PREFIX forKey:@"prefix"];
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    if (password.length) {
        [paramDic setObject:password forKey:@"password"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=findPasswordSecond"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
    
}

#pragma mark --登录
+ (void)sendLoginRequestWithMobile:(NSString*)mobile password:(NSString*)password handle:(OERegisterDataNormalHandle)handle{
    [SVProgressHUD showWithStatus:@"正在加载"];
    NSMutableDictionary * paramDic = [NSMutableDictionary new];
    NSString * token = STUserManger.defult.loginedUser.token;
    if (token.length) {
        [paramDic setObject:token forKey:@"user_token"];
    }
    [paramDic setObject:OE_PHONE_PREFIX forKey:@"prefix"];
    if (mobile.length) {
        [paramDic setObject:mobile forKey:@"mobile"];
    }
    if (password.length) {
        [paramDic setObject:password forKey:@"password"];
    }
    NSString * url = [NSString stringWithFormat:@"%@%@",releaseServerUrlHeader,@"index.php?m=Front&c=User&a=login"];
    DDLogInfo(@"url:%@",url);
    DDLogInfo(@"param:%@",paramDic);
    [[STNetWrokManger defaultClient] requestWithPath:url
                                              method:STHttpRequestTypePost
                                          parameters:paramDic
                                             success:^(NSURLSessionDataTask *operation, id responseObject) {
                                                 [SVProgressHUD dismiss];
                                                 NSDictionary * modelDic = [responseObject valueForKey:@"content"];
                                                 if (handle) {
                                                     handle(YES,@"",modelDic);
                                                 }
                                                 // DDLogInfo(@"json = \n%@",modelDic.mj_JSONString);
                                                 DDLogInfo(@"%@请求成功:resp\n%@",url,responseObject);
                                                 
                                                 
                                             } failure:^(NSString *stateCode, STError *error,NSError *originError) {
                                                 [SVProgressHUD dismiss];
                                                 [SVProgressHUD showErrorWithStatus:error.desc];
                                                 DDLogError(@"\n请求失败:\nurl:%@\nparam:%@\n失败原因:%@\n错误码:%ld",
                                                            url,paramDic,error.desc,error.code);
                                             }];
}
@end
